"""
Copyright 2009, Thomas Dejanovic, Jay Shurtz.
 
This is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this software; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA, or see the FSF site: http://www.fsf.org.
"""

#----------------------------------------------------------------------

id = "$Id: hatch_pack.py 667 2010-07-01 00:12:17Z jayshurtz $"
# $URL: http://hatch.googlecode.com/svn/trunk/hatch/hatch_nodes/obsolete/hatch_pack.py $
# $Author: jayshurtz $
version = " version ".join(id.split()[1:3])

#----------------------------------------------------------------------

from hatch_struct import *


class Pack(Struct):
    """ A Pack is a nod that contains at least one Register.  The
        Register(s) are packed into a single address location.  As
        such the total bit width of a pack cannot exceed data bus
        width which is a function of the target bus object.

        A pack cannot contain Pack(s) or any other type of hatch node.
    """

    def __init__(self, name, *childNodes, **properties):
        """ """
        Struct.__init__(self, name, *childNodes, **properties)
        for c in childNodes: # make sure child nodes passed in are only Registers.
            if  c.__class__.__name__ != Register.__name__:
                raise AttributeError, hatchNodeErrorString(self, "Packs can only have Registers as children.")  # TODO - move this to the property checker.

    def Struct(self, name, *childNodes, **properties):
        """ Do not allow creation of a struct childNode after instantiation.
        """
        raise AttributeError, hatchNodeErrorString(self, "Packs can only have Registers as children.")

    def Pack(self, name, *childNodes, **properties):
        """ Allow creation of a pack childNode after instantiation.
        """
        raise AttributeError, hatchNodeErrorString(self, "Packs can only have Registers as children.")


# Main for testing.
if __name__ == "__main__":

    # Test Pack class
    p = Pack('nombre', Register('test_f', width=10, hw='i', default=0xf), prop='prop')
    p.Register('test_d', width=10, hw='s', default=0xd)
    p.Register('test_e', width=10, hw='c', default=0xe)
            
    try:
        p.Pack('nomo')
    except AttributeError, e:
        print str(e)

    print p.info()


